package com.data.util;

import com.data.listener.SessionLoginListener;

import javax.servlet.http.HttpSession;
import java.util.Enumeration;

/**
 * 注销session
 *
 * @author: HingLo
 * @create 2017-10-12 17:12
 **/
public class ForceLogoutUtils {
    public static void forceUserLogout(String username)

    {
        HttpSession session = SessionLoginListener.sessionMap.get(username);
        if (session != null) {
            SessionLoginListener.sessionMap.remove(username);
            try {
                Enumeration e = session.getAttributeNames();
                while (e.hasMoreElements()) {
                    String sessionName = (String) e.nextElement();
                    session.removeAttribute(sessionName);
                }
                session.invalidate();
            } catch (IllegalStateException e) {
                //session 已经失效的时候
                System.out.println(e.getMessage());
            }

        }
    }
}
